Skip to content

[rshapes] Fix auto segment rounded-corner math and rounding#5883

Merged
raysan5 merged 1 commit into
raysan5:masterfrom
ghera:fix/rounded-segments-calculation
May 24, 2026
Merged

[rshapes] Fix auto segment rounded-corner math and rounding#5883
raysan5 merged 1 commit into
raysan5:masterfrom
ghera:fix/rounded-segments-calculation

Conversation

@ghera

@ghera ghera commented May 23, 2026

Copy link
Copy Markdown
Contributor

As follow-up to #5875, this PR fixes the auto- segmentation math used by the rounded rectangle path and applies the same rounding correction to the related rshapes helpers.

DrawRectangleRounded() and DrawRectangleRoundedLinesEx() use segments as the subdivision count for a single 90° corner: float stepLength = 90.0f/(float)segments;. Because of that, the correct automatic segment count is based on a quarter circle: ceil((PI/2)/th) or equivalently ceil((2*PI/th)/4).

Using /2 instead computes the subdivision count for a half-circle, which does not match how rounded rectangle corners are actually rendered.

This is also consistent with the other auto-segmentation formulas in rshapes, which scale the full-circle segment count by the portion of arc being rendered, e.g. ceilf((endAngle - startAngle)*(2*PI/th)/360.0f). Rounded rectangle corners are the 90° case of the same logic, which simplifies to /4.

This PR also moves ceilf() to the outside in the affected formulas, so rounding is applied to the final computed segment count rather than to an intermediate full-circle value. That makes the result mathematically consistent for sectors, rings, and rounded rectangle corners.

@raysan5 raysan5 changed the title rshapes: fix auto segment rounded-corner math and rounding [rshapes] Fix auto segment rounded-corner math and rounding May 24, 2026
@raysan5
raysan5 merged commit f65d5ad into raysan5:master May 24, 2026
16 checks passed
@raysan5

raysan5 commented May 24, 2026

Copy link
Copy Markdown
Owner

@ghera Nice improvement! Thanks!

@ghera
ghera deleted the fix/rounded-segments-calculation branch May 24, 2026 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants